import React from 'react';

import { HashRouter as Router, Link, Route, Switch, Redirect } from "react-router-dom";

// 引入tab de Home
import Home from "./pages/home"
import CitySelect from "./pages/citySelect"
import MapFound from "./pages/mapFound"

import { connect } from "react-redux"
import { actionInitCity } from "./store/actionCreator"

// import List from "./components/demo/List"


class App extends React.Component {
  componentDidMount() {
    //挂载完毕执行修改地图城市的名字
    console.log("城市名称", this.props.cityName)
    this.props.handleInitCity();
  }

  render() {
    return (
      <div className="App">
        {/* <List></List> */}
        {this.props.cityName && <Router>
          <section>
            <Switch>
              <Route exact path="/"  > <Redirect to="/home" ></Redirect> </Route>
              <Route path="/home" component={Home} ></Route>
              <Route path="/citySelect" component={CitySelect} ></Route>
              <Route path="/mapFound" component={MapFound} ></Route>
            </Switch>
          </section>
        </Router>}
      </div>
    );
  }
}
const mapStateToProps = (state) => ({
  cityName: state.CityReducer.cityname.name
})
const mapDispatchToProps = (dispatch) => {
  return {
    handleInitCity() {
      dispatch(actionInitCity());
    }
  }
}
export default connect(mapStateToProps, mapDispatchToProps)(App);

